package com.starchen.optimalselection.web.controller;

import com.starchen.optimalselection.common.model.ResultPage;
import com.starchen.optimalselection.common.utils.Result;
import com.starchen.optimalselection.common.model.Category;
import com.starchen.optimalselection.common.model.form.SkuInfoQueryForm;
import com.starchen.optimalselection.web.model.vo.ItemDetailVO;
import com.starchen.optimalselection.web.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 前台商品管理Controller
 * Created by daxilong on 2020/4/6.
 */
@RestController
@Api(tags = "前台商品管理")
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation(value = "综合搜索、筛选、排序")
    @GetMapping(value = "/search")
    public Result search(SkuInfoQueryForm queryParamsVo){
        ResultPage resultPage = productService.page(queryParamsVo);
        return Result.success(resultPage);
    }

    @ApiOperation("以树形结构获取所有商品分类")
    @GetMapping(value = "/categorylist")
    public Result categoryTreeList() {
        List<Category> treeList = productService.getCategoryTreeList();
        return Result.success(treeList);
    }

    @ApiOperation("获取前台商品详情")
    @GetMapping(value = "/detail/{id}")
    public Result detail(@PathVariable Long id) {
        ItemDetailVO productDetail = productService.getSkuInfo(id);
        return Result.success(productDetail);
    }

}
